package com.hubei.car.controller;

import com.hubei.car.annotation.DeleteApi;
import com.hubei.car.annotation.GetApi;
import com.hubei.car.annotation.PostApi;
import com.hubei.car.dto.req.PageCondition;
import com.hubei.car.entity.CarClassify;
import com.hubei.car.entity.CarGoods;
import com.hubei.car.entity.Result;
import com.hubei.car.service.CarGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

/**
 * @author luokangtao
 * @create 2019-08-30 15:47
 */
@RestController
@RequestMapping("/goods")
//@Api(value = "汽车商品管理",tags = "汽车商品管理")
@ApiIgnore
public class CarGoodsController {

    @Autowired
    private CarGoodsService carGoodsService;

    @PostApi(value = "/add", auth = false)
    @ApiOperation("添加商品")
    public Result add(@RequestBody CarGoods carGoods) {
        return Result.ok(carGoodsService.add(carGoods));
    }

    @PostApi(value = "/update", auth = false)
    @ApiOperation("根据主键ID修改")
    public Result update(@RequestBody CarGoods carGoods) {
        return Result.ok(carGoodsService.update(carGoods));
    }

    @DeleteApi(value = "/deleteOne/{id}", auth = false)
    @ApiOperation("根据主键ID删除")
    public Result deleteOne(@PathVariable("id") Long id) {
        return Result.ok(carGoodsService.deleteOne(id));
    }

    @GetApi(value = "/queryOne/{id}", auth = false)
    @ApiOperation("根据主键ID查询")
    public Result queryOne(@PathVariable("id") Long id) {
        return Result.ok(carGoodsService.queryOne(id));
    }

    @GetApi(value = "/updow/{id}/{updow}", auth = false)
    @ApiOperation("根据主键ID上下架")
    public Result queryOne(@PathVariable("id") Long id, @PathVariable("updow") Integer updow) {
        return Result.ok(carGoodsService.updow(id, updow));
    }

    @PostApi(value = "/queryAll", auth = false)
    @ApiOperation("条件查询商品")
    public Result queryAll(@RequestBody @Valid PageCondition pageCondition) {
        return Result.ok(carGoodsService.queryAll(pageCondition));
    }

    @PostApi(value = "/queryCars", auth = false)
    @ApiOperation("全文检索产品")
    public Result queryCars(@RequestBody @Valid PageCondition pageCondition) {
        return Result.ok(carGoodsService.queryCars(pageCondition));
    }

    @PostApi(value = "/queryRecommendImgs", auth = false)
    @ApiOperation("提取9张推荐置顶的产品默认图轮播展示")
    public Result queryRecommendImgs() {
        return Result.ok(carGoodsService.queryRecommendImgs());
    }

    @PostApi(value = "/queryCoupons", auth = false)
    @ApiOperation("获取优惠券")
    public Result queryCoupons(@RequestBody @Valid PageCondition pageCondition) {
        return Result.ok(carGoodsService.queryCoupons(pageCondition));
    }
}
